//
//  FSViewController.m
//  fanshu
//
//  Created by mh on 16/3/27.
//  Copyright © 2016年 FS. All rights reserved.
//

#import "FSTabBarController.h"
#import "FSNavController.h"
#import "FSDiscoverController.h"
#import "FSAttentionController.h"
#import "FSReleaseController.h"
#import "FSMessageViewController.h"
#import "FSMineViewController.h"


#import "FSTabBar.h"
@interface FSTabBarController ()

@end

@implementation FSTabBarController
/*
 简书主色
static func mainColor() -> UIColor {
    return UIColor(red:0.86, green:0.52, blue:0.43, alpha:1)
 */

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置子控制器
    [self setChildViewController];
    
    //利用KVC替换系统的  TabBar
    FSTabBar *tabBar = [[FSTabBar alloc] init];
    //加号按钮被点击-->回调block
    tabBar.plusBtnOnClick = ^{
        
        //创建发布控制器
        FSReleaseController *releaseVC = [[FSReleaseController alloc]init];
        //modal发布控制控制器
        [self presentViewController:releaseVC animated:YES completion:nil];
    };
    [self setValue:tabBar forKey:@"tabBar"];
}
/**
 *  设置子控制器
 */
- (void)setChildViewController{
    [self addToNavigationcontrollerWithVc:[[FSDiscoverController alloc] init] image:@"icon_tabbar_home" selectedImage:@"icon_tabbar_home_active" title:@"发现"];
    [self addToNavigationcontrollerWithVc:[[FSAttentionController alloc] init] image:@"icon_tabbar_subscription" selectedImage:@"icon_tabbar_subscription_active" title:@"关注"];
    [self addToNavigationcontrollerWithVc:[[FSMessageViewController alloc] init] image:@"icon_tabbar_notification" selectedImage:@"icon_tabbar_notification_active" title:@"消息"];
    [self addToNavigationcontrollerWithVc:[[FSMineViewController alloc] init] image:@"icon_tabbar_me" selectedImage:@"icon_tabbar_me_active" title:@"我的"];
}

- (void)addToNavigationcontrollerWithVc:(UIViewController *)Vc image:(NSString *)imageName selectedImage:(NSString *) selectedImageName title:(NSString *)title{
    [self addChildViewController:[[FSNavController alloc] initWithRootViewController:Vc]];
    Vc.title = title;
    Vc.tabBarItem.image = [UIImage imageNamed:imageName];
    Vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImageName];
    
    Vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1.0];
}

@end
